<?php
namespace app\miniapp\controller\v1;

use app\common\controller\Api;
use app\miniapp\model\GoodsModel;
use app\admin\model\Banner as BannerModel;
class Index extends Api
{
    protected $noNeedLogin = '*';

    /*
     * 首页接口
     */
    public function banner()
    {
        //轮播
        $model = new BannerModel();
        $banner = $model
            ->field('id,image')
            ->select();
        // $banner = addWebSiteUrl($banner, ['image'],config('site_web_url'));
        // $banner = addWebSiteUrl($banner, ['banner'],config('site_web_url'));
        $this->success('轮播图',[
            'banner'=>$banner,
        ]);
    }
    public function index()
    {
        // 第一部分查前五个
        $model = new GoodsModel();
        $sell =  $model
            ->where('index_type', 1)
            ->order('id DESC')
            ->limit(0, 5)
            ->select();

          // 详情页用的
//        foreach ($sell as &$v) {
//            $images = $v['images'];
//            foreach($images as &$item) {
//                $item['url'] = config('site.web_url').$item['url'];
//            }
//            $v['images'] = $images;
//        }

        // 第二部分查前五个
        $dosage = GoodsModel::where('index_type', 2) // 昂 然后尼 然后 CTRL shift K
            ->order('id DESC')
            ->limit(0, 5)
            ->select();

        // 第三部分查前两个
        $vip = GoodsModel::where('index_type', 3)
            ->order('id DESC')
            ->limit(0, 2)
            ->select();

        // 第四部分查前两个
        $reseller = GoodsModel::where('index_type', 4)
            ->order('id DESC')
            ->limit(0, 2)
            ->select();

//        // 第五部分查前六个
//        $recommend = GoodsModel::where('index_type', 5)
//            ->order('id DESC')
//            ->limit(0, 6)
//            ->select();
//
//        // 第六部分查前四个
//        $rare  = GoodsModel::where('index_type', 6)
//            ->order('id DESC')
//            ->limit(0, 4)
//            ->select();

        // 零散部分查前19个
//        $scattered  = GoodsModel::where('index_type', 7)
//            ->order('id DESC')
//            ->limit(0, 19)
//            ->select();

        $this->success('商品列表', [

            'sell' => $sell,
            'dosage' => $dosage,
            'vip' => $vip,
            'reseller' => $reseller,
           // 'recommend' => $recommend,
            //'rare' => $rare,
            //'scattered' => $scattered,

        ]);


    }
}
